var prefix='/sys/menu/';
$(document).ready(function(){
    validateMenuForm();
    //打开图标列表
    $("#ico-btn").click(function(){
        layer.open({
            type: 2,
            title:'图标列表',
            content: '/FontIcoList.html',
            area: ['480px', '90%'],
            success: function(layero, index){
                //var body = layer.getChildFrame('.ico-list', index);
                //console.log(layero, index);
            }
        });
    });
})
$.validator.setDefaults({
    submitHandler :function(){
        addMenu();
    }
});
//添加菜单
function addMenu(){
    $.ajax({
        url:prefix+'save',
        data:$('#addMenuForm').serialize(),
        type:'post',
        success:function(result){
            if(result.code=='0'){
                parent.layer.msg('添加成功', {icon: 1});
                parent.load();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                layer.alert(result.msg)
            }
        }
    });
}
function validateMenuForm(){
    var icon = "<i class='fa fa-times-circle'></i> ";
    $('#addMenuForm').validate({
        rules:{
            name:{
                required : true
            }
        },
        messages:{
            name:{
                required:icon+"请输入菜单名称"
            }
        }
    })
}